package com.cuit.controller;

import com.cuit.params.OrgAddUserParams;
import com.cuit.params.UserParams;
import com.cuit.service.OrgUserService;
import com.cuit.utils.Result;
import com.cuit.utils.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author SYE
 * @date 2023/7/29 9:51
 * @desciption: 单位用户管理
 */
@RestController
@RequestMapping("/api")
@Api(value = "单位用户管理")
public class OrgUserController {

    @Autowired
    private OrgUserService orgUserService;

    @GetMapping("/org/getAllUser/{page}/{pageSize}")
    @ApiOperation(value = "获得全部用户")
    public Result orgGetAllUser(@PathVariable("page") Integer page,
                                @PathVariable("pageSize") Integer pageSize){
        String orgId = UserThreadLocal.get().getOrgId();
        return orgUserService.orgGetAllUser(orgId,page,pageSize);
    }

    @PostMapping("/add/orgUser")
    @ApiOperation(value = "添加单位用户")
    public Result addUser(@RequestBody OrgAddUserParams orgAddUserParams){
        String orgId = UserThreadLocal.get().getOrgId();
        return orgUserService.orgAddUser(orgAddUserParams,orgId);
    }

    @PostMapping("/delete/orgUser/{userId}")
    @ApiOperation(value = "删除单位用户")
    public Result deleteOrgUser(@PathVariable("userId") String userId){
        String orgId = UserThreadLocal.get().getOrgId();
        return orgUserService.deleteOrgUser(orgId,userId);
    }

}
